package com.kong.multids.service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.kong.multids.mapper.CatMapper;
import com.kong.multids.model.Cat;
import com.kong.multids.model.CatExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author gedachao
 * @description 使用@DS注解，看数据源是否有效
 * @date 2020/5/30 16:27
 */
@Service
public class Service2Impl {
    @Autowired
    CatMapper catMapper;

    @DS("ds1")
    public List<Cat> getCats(){
        CatExample catExample = new CatExample();
        List<Cat> cats = catMapper.selectByExample(catExample);
        return cats;
    }

    @Transactional
    @DS("ds1")
    public void add(Cat cat){
        catMapper.insert(cat);
    }

}
